package com.pshcp.doctor.tool;

import com.framework.exception.BizException;
import com.framework.thread.ReqComTool;
import com.framework.tool.CommonTool;
import com.framework.util.SystemUtil;
import com.pshcp.doctor.ao.messagenotificationsettings.SaveDoctorMessageNotificationSettingsAO;
import com.pshcp.domain.model.DoctorMessageNotificationSettings;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/3 21:43
 */
public class DoctorMessageNotificationSettingsTool {

    public static DoctorMessageNotificationSettings buildDefualtDoctorMessageNotificationSettings() {
        DoctorMessageNotificationSettings doctorMessageNotificationSettings = new DoctorMessageNotificationSettings();
        doctorMessageNotificationSettings.setDoctorId(ReqComTool.getUserId());
        doctorMessageNotificationSettings.setDisturbFlag(0);
        doctorMessageNotificationSettings.setStartTime(null);
        doctorMessageNotificationSettings.setEndTime(null);
        return doctorMessageNotificationSettings;
    }

    public static void checkSaveDoctorMessageNotificationSettings(SaveDoctorMessageNotificationSettingsAO saveDoctorMessageNotificationSettingsAO) throws BizException {
        CommonTool.checkObj(saveDoctorMessageNotificationSettingsAO.getDisturbFlag(), "10070001");
        if (saveDoctorMessageNotificationSettingsAO.getDisturbFlag() == 1) {
            CommonTool.checkObj(saveDoctorMessageNotificationSettingsAO.getStartTime(), "10070002");
            CommonTool.checkObj(saveDoctorMessageNotificationSettingsAO.getEndTime(), "10070003");
        }
    }

    public static DoctorMessageNotificationSettings buildSaveDoctorMessageNotificationSettings(SaveDoctorMessageNotificationSettingsAO saveDoctorMessageNotificationSettingsAO) {
        DoctorMessageNotificationSettings doctorMessageNotificationSettings = new DoctorMessageNotificationSettings();
        doctorMessageNotificationSettings.setDoctorId(ReqComTool.getUserId());
        doctorMessageNotificationSettings.setDisturbFlag(saveDoctorMessageNotificationSettingsAO.getDisturbFlag());
        if (saveDoctorMessageNotificationSettingsAO.getDisturbFlag() == 1) {
            doctorMessageNotificationSettings.setStartTime(saveDoctorMessageNotificationSettingsAO.getStartTime());
            doctorMessageNotificationSettings.setEndTime(saveDoctorMessageNotificationSettingsAO.getEndTime());
        }
        return doctorMessageNotificationSettings;
    }

    public static DoctorMessageNotificationSettings buildSaveDoctorMessageNotificationSettings(DoctorMessageNotificationSettings doctorMessageNotificationSettings, SaveDoctorMessageNotificationSettingsAO saveDoctorMessageNotificationSettingsAO) {
        doctorMessageNotificationSettings.setDisturbFlag(saveDoctorMessageNotificationSettingsAO.getDisturbFlag());
        if (saveDoctorMessageNotificationSettingsAO.getDisturbFlag() == 1) {
            doctorMessageNotificationSettings.setStartTime(saveDoctorMessageNotificationSettingsAO.getStartTime());
            doctorMessageNotificationSettings.setEndTime(saveDoctorMessageNotificationSettingsAO.getEndTime());
        }
        return doctorMessageNotificationSettings;
    }
}
